home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / OpenDoc 1.2b2c1 / TestParts / Clock / ClockFrm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-01  |  43.6 KB  |  1,748 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ClockFrm.cpp
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Owned by:    Richard Rodseth
  7.  
  8.     Copyright:    © 1995 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <3>     10/8/96    TJ        Removed include of PartWrap.xh
  13.          <2>     6/20/96    JP        1323103: made some logging optional
  14.         <21>     11/2/95    RR        Mods to fix Editor swapping
  15.         <20>    10/18/95    RR        1289153: Recover from exceptions creating
  16.                                     windows. Store fPlatformWindow pointer in
  17.                                     ClockFrame, so we can get to it even if
  18.                                     odWindow isn't successfully created
  19.         <19>    10/17/95    jpa        Don't crash closing frames w/o windows
  20.                                     [1289153]
  21.         <18>     10/5/95    TJ        Opps, the last comment was wrong. I removed
  22.                                     an embeded  Comment.
  23.         <17>     10/5/95    TJ        Linked in the GX shared library.
  24.         <16>     9/21/95    RR        Delete facet iterator
  25.         <15>     9/12/95    RR        Various activation problems. Added a
  26.                                     floating window
  27.         <14>      9/1/95    RR        # 1244639 Set and use fShouldDeleteWindow.
  28.                                     Set fNeedsFoci false
  29.         <13>     7/10/95    RR        Misc. cleanup and bug fixes for shared
  30.                                     window
  31.         <12>      7/7/95    RR        Some refactoring. Fix
  32.                                     CreatePropObjSpecifier to deal with
  33.                                     non-persistent frame. Set source frame of
  34.                                     dialogs.
  35.         <11>      7/3/95    RR        1242642 BB: refcounting. NULL out
  36.                                     TempODWindow after calling CloseAndRemove
  37.         <10>     6/30/95    RR        1242642 BB Ref counting fixes. Display
  38.                                     settings window is saved as an ID, not a
  39.                                     window
  40.          <9>     6/28/95    RR        1242642 BB Mostly ref counting
  41.          <8>     6/25/95    TÇ        1242642 BB: Turn on ODDebug warning if
  42.                                     refcount is wrong in
  43.                                     ODRefCntObjectsomUninit.
  44.          <7>     6/20/95    JBS        1257315 change Facet::AcquireWindow to
  45.                                     GetWindow
  46.          <6>     6/13/95    JP        Recordable Clock
  47.          <5>     6/12/95    TJ        Included ODDebug.h
  48.          <4>      6/8/95    jpa        Use temp objects (TempODShape,
  49.                                     TempODFrame). [1246062]
  50.          <3>      6/8/95    RR        #1257260 Collapse base classes. #1214898
  51.                                     StdTypes.r -> ODTypes.r
  52.          <2>      6/3/95    TJ        Added #includes for compile with out PCH
  53.          <1>     5/31/95    RR        first checked in
  54.  
  55.     To Do:
  56.     In Progress:
  57.         
  58. */
  59.  
  60. #ifndef _ALTPOINT_
  61. #include "AltPoint.h"            // Use C++ savvy ODPoint and ODRect
  62. #endif
  63.  
  64. #ifndef _CLOCKFRM_
  65. #include "ClockFrm.h"
  66. #endif
  67.  
  68. #ifndef _CLOCKGBL_
  69. #include "ClockGbl.h"
  70. #endif
  71.  
  72. #ifndef _CLOCKPRT_
  73. #include "ClockPrt.h"
  74. #endif
  75.  
  76. #ifndef _CLOCKDEF_
  77. #include "ClockDef.h"
  78. #endif
  79.  
  80. #ifndef _PLFMDEF_
  81. #include "PlfmDef.h"
  82. #endif
  83.  
  84.  
  85. #ifndef _SIHELPER_
  86. #include "SIHelper.h"
  87. #endif
  88.  
  89. #ifndef SOM_Module_OpenDoc_Foci_defined
  90. #include <Foci.xh>
  91. #endif
  92.  
  93. #ifndef _USERSRCM_
  94. #include "UseRsrcM.h"
  95. #endif
  96.  
  97. #ifndef SOM_ODFocusSet_xh
  98. #include <FocusSet.xh>
  99. #endif
  100.  
  101. #ifndef SOM_Module_OpenDoc_StdProps_defined
  102. #include <StdProps.xh>
  103. #endif
  104.  
  105. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  106. #include <StdTypes.xh>
  107. #endif
  108.  
  109. #ifndef _ODTYPES_
  110. #include <ODTypes.h>
  111. #endif
  112.  
  113. #ifndef SOM_Module_OpenDoc_StdDefs_defined
  114. #include <StdDefs.xh>
  115. #endif
  116.  
  117. #ifndef SOM_ODDraft_xh
  118. #include <Draft.xh>
  119. #endif
  120.  
  121. #ifndef SOM_ODDocument_xh
  122. #include <Document.xh>
  123. #endif
  124.  
  125. #ifndef SOM_ODContainer_xh
  126. #include <ODCtr.xh>
  127. #endif
  128.  
  129. #ifndef SOM_ODStorageUnit_xh
  130. #include <StorageU.xh>
  131. #endif
  132.  
  133. #ifndef SOM_ODStorageUnitView_xh
  134. #include <SUView.xh>
  135. #endif
  136.  
  137. #ifndef SOM_ODStorageUnitCursor_xh
  138. #include <SUCursor.xh>
  139. #endif
  140.  
  141. #ifndef SOM_ODSession_xh
  142. #include <ODSessn.xh>
  143. #endif
  144.  
  145. #ifndef SOM_ODWindowState_xh
  146. #include <WinStat.xh>
  147. #endif
  148.  
  149. #ifndef SOM_ODFrame_xh
  150. #include <Frame.xh>
  151. #endif
  152.  
  153. #ifndef SOM_ODFacet_xh
  154. #include <Facet.xh>
  155. #endif
  156.  
  157. #ifndef SOM_ODFrameFacetIterator_xh
  158. #include <FrFaItr.xh>
  159. #endif
  160.  
  161. #ifndef _ORDCOLL_
  162. #include "OrdColl.h"
  163. #endif
  164.  
  165. #ifndef SOM_ODDispatcher_xh
  166. #include <Disptch.xh>
  167. #endif
  168.  
  169. #ifndef _ODUTILS_
  170. #include <ODUtils.h>
  171. #endif
  172.  
  173. #ifndef SOM_ODMenuBar_xh
  174. #include <MenuBar.xh>
  175. #endif
  176.  
  177. #ifndef SOM_Module_OpenDoc_Commands_defined
  178. #include <CmdDefs.xh>
  179. #endif
  180.  
  181. #ifndef _ITEXT_
  182. #include <IText.h>
  183. #endif
  184.  
  185. #ifndef _ISOSTRING_
  186. #include "ISOStr.h"
  187. #endif
  188.  
  189. #ifndef SOM_ODMessageInterface_xh
  190. #include <MssgIntf.xh>
  191. #endif
  192.  
  193. #ifndef _AEOBJECTS_
  194. #include "AEObjects.h"
  195. #endif
  196.  
  197. #ifndef _FOCUSLIB_
  198. #include "FocusLib.h"
  199. #endif
  200.  
  201. #ifndef SOM_ODArbitrator_xh
  202. #include <Arbitrat.xh>
  203. #endif
  204.  
  205. #ifndef SOM_ODWindow_xh
  206. #include <Window.xh>
  207. #endif
  208.  
  209. #ifndef SOM_ODShape_xh
  210. #include <Shape.xh>
  211. #endif
  212.  
  213. #ifndef SOM_ODTransform_xh
  214. #include <Trnsform.xh>
  215. #endif
  216.  
  217. #ifndef _EXCEPT_
  218. #include "Except.h"
  219. #endif
  220.  
  221. #ifndef __MENUS__
  222. #include <Menus.h>
  223. #endif
  224.  
  225. #ifndef __OSUTILS__
  226. #include <OSUtils.h>
  227. #endif
  228.  
  229. #ifndef __TOOLUTILS__
  230. #include <ToolUtils.h>
  231. #endif
  232.  
  233. #ifndef __FONTS__
  234. #include <Fonts.h>
  235. #endif
  236.  
  237. #ifndef __SCRIPT__
  238. #include <Script.h>
  239. #endif
  240.  
  241. #ifndef __TYPES__
  242. #include <Types.h>
  243. #endif
  244.  
  245. #ifndef __PACKAGES__
  246. #include <Packages.h>
  247. #endif
  248.  
  249. #ifndef __RESOURCES__
  250. #include <Resources.h>
  251. #endif
  252.  
  253. #ifndef __DIALOGS__
  254. #include "Dialogs.h"
  255. #endif
  256.  
  257. #ifndef __TEXTEDIT__
  258. #include <TextEdit.h>
  259. #endif
  260.  
  261. #ifndef __PACKAGES__
  262. #include <Packages.h>
  263. #endif
  264.  
  265. #ifndef __STRINGS__
  266. #include <Strings.h>
  267. #endif
  268.  
  269. #ifndef __FP__
  270. #include <Fp.h>
  271. #endif
  272.  
  273. #include <string.h>
  274.  
  275. #ifndef _ODDEBUG_
  276. #include "ODDebug.h"    
  277. #endif
  278.  
  279. #ifndef _STDTYPIO_
  280. #include "StdTypIO.h"
  281. #endif
  282.  
  283. #ifndef _INFOUTIL_
  284. #include <InfoUtil.h>
  285. #endif
  286.  
  287. #ifndef _WINUTILS_
  288. #include "WinUtils.h"
  289. #endif
  290.  
  291. #ifndef _ITEXT_
  292. #include <IText.h>
  293. #endif
  294.  
  295. #ifndef _PASCLSTR_
  296. #include "PasclStr.h"
  297. #endif
  298.  
  299. #ifndef _STORUTIL_
  300. #include <StorUtil.h>
  301. #endif
  302.  
  303. #ifndef _POUTILS_
  304. #include <POUtils.h>    // for UpdateModificationInfo
  305. #endif
  306.  
  307. #ifndef _TEMPOBJB_
  308. #include <TempObj.h>
  309. #endif
  310.  
  311. //#ifndef SOM_ODPartWrapper_xh
  312. //#include "PartWrap.xh"
  313. //#endif
  314.  
  315. #pragma segment ClockFrame
  316.  
  317. //=========================================================================
  318. // ClockFrame
  319. //=========================================================================
  320.  
  321. ClockFrame::ClockFrame()
  322. {
  323.     fArrowCursor = (ODQDGlobals.arrow);                
  324.     fFrame = kODNULL;
  325.     fClockPart = kODNULL;
  326.     fHasFoci = kODFalse; 
  327.     fNeedsFoci = kODFalse; 
  328.     fFocusSet = kODNULL;
  329.     fWindowID = 0;
  330.     fPlatformWindow = kODNULL;
  331.     fShouldDeleteWindow = kODFalse;
  332.     fShouldHideOnSuspend = kODFalse;
  333.     fShowWindowOnResume = kODFalse;
  334.     fShowWindowOnFocus = kODFalse;
  335.     fInBackground = kODFalse;
  336. }
  337.  
  338.  
  339. ClockFrame::~ClockFrame()
  340. {
  341. }
  342.  
  343.  
  344. void ClockFrame::InitClockFrame(Environment* ev, 
  345.                                 ODSession* session,
  346.                                 ODFrame* frame, 
  347.                                 ClockPart* clockPart)
  348. {
  349.     fSession = session;
  350.     fArbitrator = fSession->GetArbitrator(ev);
  351.     fDispatcher = fSession->GetDispatcher(ev);
  352.     fWindowState = fSession->GetWindowState(ev);
  353.  
  354.     fFrame = frame;
  355.     fClockPart = clockPart;
  356.  
  357.     fFocusSet = fArbitrator->CreateFocusSet(ev);
  358.  
  359.     fSelectionFocus = fSession->Tokenize(ev, kODSelectionFocus);
  360.     fMenuFocus = fSession->Tokenize(ev, kODMenuFocus);
  361.     fKeyFocus = fSession->Tokenize(ev, kODKeyFocus);
  362.     fModalFocus = fSession->Tokenize(ev, kODModalFocus);
  363.     fShouldDeleteWindow = frame->IsRoot(ev);
  364.     fShouldHideOnSuspend = kODFalse;
  365. }
  366.  
  367. void ClockFrame::MouseEnter(Environment* ev, ODFacet* facet, ODPoint* where)
  368. {
  369.     ODUnused(facet);
  370.     ODUnused(where);
  371.     SetCursor(&fArrowCursor);
  372. }
  373.  
  374. void ClockFrame::MouseWithin(Environment* ev, ODFacet* facet, ODPoint* where)
  375. {
  376.     ODUnused(facet);
  377.     ODUnused(where);
  378. }
  379.  
  380. void ClockFrame::MouseLeave(Environment* ev, ODFacet* facet)
  381. {
  382.     ODUnused(facet);
  383.     SetCursor(&fArrowCursor);
  384. }
  385.  
  386. ODID ClockTimeFrame::ViewInWindow(Environment *ev)
  387. {
  388.     ODWindow* window = kODNULL;
  389.     
  390.     window = fWindowState->AcquireWindow(ev, fWindowID);
  391.     if (window)
  392.     {
  393.         window->Select(ev);
  394.         ODReleaseObject(ev, window);    
  395.     }
  396.     else
  397.     {
  398.         WindowProperties props;
  399.         fClockPart->GetDefaultWindowProperties(ev, &props, fFrame);
  400.         window = fClockPart->CreateWindow(ev, props, kODNULL);
  401.         fWindowID = window->GetID(ev);
  402.         window->Open(ev);
  403.         window->Show(ev);
  404.         window->Select(ev);    
  405.         ODReleaseObject(ev, window);        
  406.     }
  407.     return fWindowID;
  408. }
  409.  
  410. //------------------------------------------------------------------------------
  411. // ClockFrame::BeginRelinquishFocus
  412. //------------------------------------------------------------------------------
  413.  
  414.  
  415. ODBoolean ClockFrame::BeginRelinquishFocus(Environment *ev,
  416.                                              ODTypeToken focus,
  417.                                              ODFrame* proposedFrame)
  418. {
  419.     ODUnused(proposedFrame);
  420.     ODBoolean result = kODFalse;
  421.  
  422.     ODPart* part = proposedFrame->AcquirePart(ev);
  423.     if ((focus == fModalFocus) && (part != fClockPart->GetPartWrapper()))
  424.         result = kODFalse;
  425.     else
  426.         result = kODTrue;
  427.     ODReleaseObject(ev, part);
  428.     return result;
  429. }
  430.     
  431.     
  432. //------------------------------------------------------------------------------
  433. // ClockFrame::CommitRelinquishFocus
  434. //------------------------------------------------------------------------------
  435.  
  436.  
  437. void ClockFrame::CommitRelinquishFocus(Environment *ev,
  438.                                          ODTypeToken focus,
  439.                                          ODFrame* proposedFrame)
  440. {
  441.     //if (proposedFrame->GetPart(ev) != fClockPart->GetPartWrapper())
  442.     this->FocusLost(ev, focus, proposedFrame);
  443. }
  444.     
  445.                             
  446. //------------------------------------------------------------------------------
  447. // ClockFrame::AbortRelinquishFocus
  448. //------------------------------------------------------------------------------
  449.  
  450.  
  451. void ClockFrame::AbortRelinquishFocus(Environment *ev,
  452.                                          ODTypeToken    focus,
  453.                                          ODFrame* proposedFrame)
  454. {
  455.     ODUnused(focus);
  456.     ODUnused(proposedFrame);
  457. }
  458.             
  459.                               
  460. //------------------------------------------------------------------------------
  461. // ClockFrame::FocusAcquired
  462. //------------------------------------------------------------------------------
  463.  
  464.  
  465. void ClockFrame::FocusAcquired(Environment *ev,
  466.                                  ODTypeToken    focus)
  467. {
  468. /*    if (focus == fSelectionFocus) 
  469.     {
  470.         fHasFoci = kODTrue;
  471.     }
  472.     else if (focus == fMenuFocus) 
  473.         fClockPart->InstallMenus(ev);
  474. */
  475. }    
  476.  
  477.  
  478. //------------------------------------------------------------------------------
  479. // ClockFrame::FocusLost
  480. //------------------------------------------------------------------------------
  481.  
  482.  
  483. void ClockFrame::FocusLost(Environment *ev,
  484.                              ODTypeToken    focus, ODFrame* proposedFrame)
  485. {
  486.     if ( (focus == fSelectionFocus) ||
  487.         (focus == fMenuFocus) ||
  488.         (focus == fKeyFocus) )
  489.     {
  490.         fHasFoci = kODFalse;
  491.     }    
  492.         
  493.     if (focus == fSelectionFocus) 
  494.     {    
  495.         this->LostSelectionFocus(ev, proposedFrame);
  496.  
  497.     }
  498. }    
  499.  
  500. void ClockFrame::LostSelectionFocus(Environment* ev, ODFrame* proposedFrame)
  501. {
  502.     ODBoolean samePart = 
  503.         (proposedFrame && (proposedFrame->GetPresentation(ev) == fClockPart->fTimePresentation));
  504.     if (!samePart)
  505.         gClockGlobals->SuspendWindows(ev, kODFalse);
  506. }
  507.  
  508. void ClockFrame::AcquiredSelectionFocus(Environment* ev)
  509. {
  510.     gClockGlobals->AcquiringFocus(ev, fFrame);
  511.     gClockGlobals->ResumeWindows(ev, kODFalse);
  512. }
  513.  
  514. void ClockFrame::Add(Environment* ev)
  515. {
  516. }
  517.  
  518. void ClockFrame::Connect(Environment* ev)
  519. {
  520. }
  521.  
  522. void ClockFrame::FacetAdded(Environment* ev, ODFacet* facet) 
  523. {
  524.     if (fShouldDeleteWindow)
  525.     {
  526.         ODWindow* window = facet->GetWindow(ev);
  527.         fPlatformWindow = window ? window->GetPlatformWindow(ev) : kODNULL;
  528.     }
  529. }
  530.  
  531. void ClockFrame::Remove(Environment* ev)
  532. {
  533.     fArbitrator->RelinquishFocusSet(ev, fFocusSet,fFrame);
  534.     ODWindow* window = fWindowState->AcquireWindow(ev, fWindowID); // -- TÇ: released by CloseAndRemove
  535.     if (window)
  536.     {
  537.         window->CloseAndRemove(ev);
  538.         // ODReleaseObject(ev, window); // -- TÇ: released by CloseAndRemove
  539.     }
  540.     
  541.     this->DisposePlatformWindow(ev);
  542. }
  543.  
  544. void ClockFrame::Close(Environment* ev)
  545. {
  546.     fArbitrator->RelinquishFocusSet(ev, fFocusSet,fFrame);
  547.     ODWindow* window = fWindowState->AcquireWindow(ev, fWindowID); // -- TÇ: released by CloseAndRemove
  548.     if (window)
  549.     {
  550.         window->Close(ev);
  551.         // ODReleaseObject(ev, window); // -- TÇ: released by Close
  552.     }
  553.     
  554.     this->DisposePlatformWindow(ev);
  555. }
  556.  
  557. void ClockFrame::DisposePlatformWindow(Environment *ev)
  558. {
  559.     if (fShouldDeleteWindow)
  560.     {
  561.         CloseWindow(fPlatformWindow);
  562.         ODDisposePtr(fPlatformWindow);
  563.     }
  564. }
  565.  
  566. void  ClockFrame::AdjustMenus(Environment *ev)
  567. {
  568.     fClockPart->AdjustMenus(ev);
  569. }
  570.  
  571. ODBoolean ClockFrame::HandleMenuEvent(Environment* ev, ODEventData* event)
  572. {
  573.     return fClockPart->HandleMenuEvent(ev, event, fFrame);
  574. }
  575.  
  576. //=========================================================================
  577. // ClockTimeFrame
  578. //=========================================================================
  579.  
  580. ClockTimeFrame::ClockTimeFrame()
  581. {
  582.     fCrossCursor = (ODQDGlobals.arrow);        
  583.     fLastTime = 0;
  584. };
  585.  
  586. ClockTimeFrame::~ClockTimeFrame()
  587. {
  588. }
  589.  
  590. void ClockTimeFrame::InitClockTimeFrame(Environment* ev, 
  591.                                         ODSession* session,
  592.                                         ODFrame* frame, 
  593.                                         ClockPart* clockPart)
  594. {
  595.     this->InitClockFrame(ev, session, frame, clockPart);
  596.     fCrossCursor = **GetCursor(crossCursor);    
  597.  
  598.     fFocusSet->Add(ev, fKeyFocus);
  599.     fFocusSet->Add(ev, fMenuFocus);
  600.     fFocusSet->Add(ev, fSelectionFocus);
  601.  
  602.     if (frame->IsRoot(ev))
  603.         fNeedsFoci = kODTrue;
  604. }
  605.  
  606. void ClockTimeFrame::MouseEnter(Environment* ev, ODFacet* facet, ODPoint* where)
  607. {
  608.     ODUnused(where);
  609.     ODUnused(facet);
  610.     //SetCursor(&fCrossCursor);
  611.     SetCursor(&fArrowCursor);
  612. }
  613.  
  614. void ClockTimeFrame::Idle(Environment* ev, ODEventData* event)
  615. {
  616.     ODBoolean    wasHandled = kODFalse;
  617.     ODULong    tTickCount = 0;
  618.  
  619.     GetDateTime( &tTickCount );
  620.  
  621.  
  622.     DateTimeRec time;
  623.     DateTimeRec lastTime;
  624.     
  625.     ::SecondsToDate(tTickCount, &time);
  626.     ::SecondsToDate(fLastTime, &lastTime);
  627.     
  628.     if (lastTime.second != time.second)
  629.     //if ( (tTickCount + 60) > fLastTime )
  630.     {
  631.         ODFrameFacetIterator* facets = fFrame->CreateFacetIterator(ev);
  632.         for ( ODFacet* facet = facets->First(ev);
  633.                 facets->IsNotComplete(ev);
  634.                 facet = facets->Next(ev) )
  635.         {
  636.             this->UpdateTime(ev, facet, tTickCount);    
  637.         }
  638.         delete facets;
  639.     }
  640.  
  641.     if (fClockPart->AlarmEnabled() ) // &&  (tTickCount % 10 == 0))
  642.     {
  643.             if (tTickCount % 10 == 0)
  644.                 gClockGlobals->CloseDisplaySettingsWindow(ev);
  645.             if (tTickCount % 12 == 0)
  646.                 gClockGlobals->OpenDisplaySettingsDialog(ev, fFrame);
  647.         /*
  648.         TempODFrame focusFrame = fArbitrator->AcquireFocusOwner(ev, fModalFocus);
  649.  
  650.         if (focusFrame == fFrame)
  651.             SysBeep(2);
  652.         else if (fArbitrator->RequestFocus(ev, fModalFocus,fFrame))
  653.         {
  654.             ODSLong        savedRefNum;
  655.             BeginUsingLibraryResources(savedRefNum);
  656.             ParamText("\pWake Up!",0,0,0);
  657.             ModalFilterUPP modalFilter = NewModalFilterProc(ClockDialogFilter);
  658.             fWindowState->DeactivateFrontWindows(ev);
  659.             Alert(kClock_AlarmDialogID, modalFilter);
  660.             DisposeRoutineDescriptor(modalFilter);
  661.             fWindowState->ActivateFrontWindows(ev);
  662.             fArbitrator->TransferFocus(ev, fModalFocus,fFrame, focusFrame);            
  663.             EndUsingLibraryResources(savedRefNum);
  664.             
  665.         }
  666.         else
  667.             SysBeep(2);
  668.         */
  669.     }
  670. }
  671.  
  672. void ClockTimeFrame::Draw(Environment* ev, ODFacet* facet, ODShape* invalShape)
  673. {
  674.     if (facet)
  675.     {
  676.         CFocus    focus(ev, facet);    // Set port, origin, clip
  677.             
  678.         this->DrawClockFace(ev, facet);
  679.         this->DrawTime(ev, facet, fLastTime);
  680.     }
  681.  
  682. }
  683.  
  684. void ClockTimeFrame::DrawDigitalTime(Environment* ev, ODFacet* facet, ODULong tickCount)
  685. {
  686.     // Assumes port is set
  687.     Str255    tTimeString;        // pascal string holding date to draw
  688.         
  689.     TextFont(fClockPart->GetFont() );
  690.     TextFace(fClockPart->GetStyle() );
  691.     TextMode(srcCopy);
  692.     TextSize(fClockPart->GetSize() );
  693.     
  694.     IUTimeString( tickCount, kODTrue, tTimeString );
  695.     
  696.     if (fClockPart->GetLastAscent() == 0)
  697.     {
  698.         FontInfo fontIRec;
  699.         GetFontInfo( &fontIRec );
  700.         fClockPart->SetLastAscent(fontIRec.ascent);
  701.     }
  702.     
  703.     MoveTo( 2, fClockPart->GetLastAscent() + 1 );
  704.     DrawString( tTimeString );
  705.     
  706.     TextFace( normal );
  707.     TextFont( geneva );
  708.     TextMode( srcOr );
  709.     TextSize( 12 );
  710. }
  711.  
  712. void ClockTimeFrame::UpdateTime(Environment* ev, ODFacet* facet, ODULong tickCount)
  713. {
  714.     CFocus focus(ev, facet);
  715.     if (fClockPart->IsAnalog())
  716.         this->UpdateClockHands(ev, facet, tickCount);
  717.     else
  718.         this->DrawDigitalTime(ev, facet, tickCount);
  719.     fLastTime = tickCount;
  720. }
  721.  
  722. void ClockTimeFrame::DrawTime(Environment* ev, ODFacet* facet, ODULong tickCount)
  723. {
  724.     if (fClockPart->IsAnalog())
  725.         this->DrawClockHands(ev, facet, tickCount);
  726.     else
  727.         this->DrawDigitalTime(ev, facet, tickCount);
  728. }
  729.  
  730. ODBoolean ClockTimeFrame::HandleMouseDown(Environment* ev, ODFacet* facet, ODEventData* event)
  731. {
  732.     ODBoolean wasHandled = kODFalse;
  733.  
  734.     if (!facet->GetWindow(ev)->IsActive(ev))
  735.         facet->GetWindow(ev)->Select(ev);
  736.     else
  737.     {
  738.         // A test: option-click doesn't go to container, and clock beeps
  739.         ODBoolean modified = (event->modifiers & optionKey) != 0;
  740.         if (modified)
  741.         {    
  742.             SysBeep(2);
  743.         } 
  744.         else
  745.             this->Activate(ev);
  746.     }
  747.  
  748.     return wasHandled;
  749. }
  750.  
  751. ODBoolean ClockTimeFrame::HandleMouseUp(Environment* ev, ODFacet* facet, ODEventData* event)
  752. {
  753.     if ( facet == kODNULL )
  754.         return kODTrue;
  755.     if (!facet->GetWindow(ev)->IsActive(ev))
  756.         facet->GetWindow(ev)->Select(ev);
  757.     else
  758.     {
  759.         this->Activate(ev);
  760.     }
  761.     return kODTrue;
  762. }
  763.  
  764.  
  765. void ClockTimeFrame::AcquiredRequestedFoci(Environment* ev)
  766. {
  767.     this->AcquiredSelectionFocus(ev);
  768.     fClockPart->InstallMenus(ev);
  769. }
  770.  
  771. void ClockFrame::Activate(Environment* ev)
  772. {
  773.     if (!fHasFoci)
  774.     {
  775.         ODBoolean succeeded = kODFalse;
  776.                             
  777.         succeeded = fArbitrator->RequestFocusSet(ev, fFocusSet,fFrame);
  778.                 
  779.         if (succeeded)
  780.         {
  781.             fHasFoci = kODTrue;
  782.             fNeedsFoci = kODFalse;
  783.             this->AcquiredRequestedFoci(ev);
  784.         }
  785.     }
  786. }
  787.  
  788. void ClockFrame::ActivatingWindow(Environment* ev, ODFacet* facet, ODEventData* event) 
  789. {
  790. #if defined(ODDebug) && ODDebugLayers
  791.     somPrintf("Activating window of Clock\n");
  792. #endif
  793.  
  794.     if (fNeedsFoci)
  795.     {
  796.         this->Activate(ev);
  797.     }
  798.     fNeedsFoci = kODFalse;
  799. }
  800.  
  801. void ClockFrame::DeactivatingWindow(Environment* ev, ODFacet* facet, ODEventData* event)
  802. {
  803. #if defined(ODDebug) && ODDebugLayers
  804.     somPrintf("Deactivating window of Clock\n");
  805. #endif
  806.  
  807.     if (fHasFoci) // (fFrame == fArbitrator->AcquireFocusOwner(ev, fSelectionFocus))
  808.     {
  809.         fNeedsFoci = kODTrue;
  810.     }
  811.     else
  812.         fNeedsFoci = kODFalse;
  813. }
  814.  
  815. void ClockFrame::SuspendFocus(Environment* ev)
  816. {
  817. #if defined(ODDebug) && ODDebugLayers
  818.     somPrintf("ClockFrame::SuspendFocus - should hide %x\n", fShouldHideOnSuspend);
  819. #endif
  820.     if (fFrame->IsRoot(ev) && fShouldHideOnSuspend)
  821.     {    
  822.         TempODWindow window = fFrame->AcquireWindow(ev);
  823.         if (window->IsShown(ev))
  824.         {
  825.             window->Hide(ev);
  826.             fShowWindowOnFocus = kODTrue;
  827.         }
  828.         else
  829.         {
  830.             fShowWindowOnFocus = kODFalse;
  831.         }
  832.     }
  833. }
  834.  
  835. void ClockFrame::ResumeFocus(Environment* ev)
  836. {
  837. #if defined(ODDebug) && ODDebugLayers
  838.     somPrintf("ClockFrame::ResumeFocus - should show %x\n", fShowWindowOnFocus);
  839. #endif
  840.     if (fFrame->IsRoot(ev) && fShouldHideOnSuspend)
  841.     {    
  842.         TempODWindow window = fFrame->AcquireWindow(ev);
  843.         if (fShowWindowOnFocus && !fInBackground)
  844.         {
  845.             fShowWindowOnFocus = kODFalse; 
  846.             window->Show(ev);
  847.         }
  848.     }
  849. }
  850.  
  851. void ClockFrame::SuspendProcess(Environment* ev)
  852. {
  853.     fInBackground = kODTrue;
  854. #if defined(ODDebug) && ODDebugLayers
  855.     somPrintf("ClockFrame::SuspendProcess - should hide %x\n", fShouldHideOnSuspend);
  856. #endif
  857.     if (fFrame->IsRoot(ev) && fShouldHideOnSuspend)
  858.     {    
  859.         TempODWindow window = fFrame->AcquireWindow(ev);
  860.         if (window->IsShown(ev))
  861.         {
  862.             fShowWindowOnResume = kODTrue;
  863.             window->Hide(ev);
  864.         }
  865.         else
  866.         {
  867.             fShowWindowOnResume = kODFalse; 
  868.         }
  869.     }
  870. }
  871.  
  872. void ClockFrame::ResumeProcess(Environment* ev)
  873. {
  874.     fInBackground = kODFalse;
  875. #if defined(ODDebug) && ODDebugLayers
  876.     somPrintf("ClockFrame::ResumeProcess - should show %x\n", fShowWindowOnResume);
  877. #endif
  878.     if (fFrame->IsRoot(ev) && fShouldHideOnSuspend)
  879.     {    
  880.         TempODWindow window = fFrame->AcquireWindow(ev);
  881.         if (fShowWindowOnResume)
  882.         {
  883.             fShowWindowOnResume = kODFalse; // It may be hidden by user before next Suspend
  884.             fShowWindowOnFocus = kODFalse;
  885.             window->Show(ev);
  886.         }
  887.     }
  888. }
  889.  
  890.  
  891. void  ClockTimeFrame::AdjustMenus(Environment *ev)
  892. {
  893.     TempODWindow window = fFrame->AcquireWindow(ev);
  894.     fClockPart->AdjustMenus(ev);
  895.  
  896.     fClockPart->GetMenuBar()->EnableCommand(ev, kODCommandViewAsWin, !fFrame->IsRoot(ev));
  897.     fClockPart->GetMenuBar()->EnableCommand(ev, cNewView, fFrame->IsRoot(ev) && window->IsRootWindow(ev));
  898. }
  899.  
  900. void ClockTimeFrame::Adjust(Environment* ev)
  901. {
  902.     this->AdjustFrameShape(ev);
  903. }
  904.  
  905. //------------------------------------------------------------------------------
  906. // ClockTimeFrame: HandleMenuEvent
  907. //------------------------------------------------------------------------------
  908.  
  909.  
  910. ODBoolean ClockTimeFrame::HandleMenuEvent(Environment *ev, ODEventData* event)
  911. {
  912.     ODBoolean wasHandled = kODTrue;
  913.  
  914.     long menuResult = event->message;
  915.     short menu = HiWord(menuResult);
  916.     short item = LoWord(menuResult);
  917.     ODCommandID command = fClockPart->GetMenuBar()->GetCommand(ev, menu, item);
  918.  
  919.         switch (command)
  920.         {
  921.             //case kODCommandAbout:
  922.             //    fClockPart->ShowAboutBox(ev, fFrame);
  923.             wasHandled = kODTrue;
  924.                 break;
  925.             case kODCommandViewAsWin:
  926.                 this->ViewInWindow(ev); 
  927.             wasHandled = kODTrue;
  928.                 break;
  929.             case kODCommandClose:
  930.                 wasHandled = fClockPart->CloseWindow(ev, fFrame);
  931.                 break;
  932.         /*case cSynchronize:
  933.             fClockPart->ShowSynchDialog(ev);
  934.             wasHandled = kODTrue;
  935.             break;
  936.         case cShowAlarmSettings:
  937.             fClockPart->ShowAlarmSettingsDialog(ev);
  938.             wasHandled = kODTrue;
  939.             break;
  940.         case cShowDisplaySettings:
  941.             gClockGlobals->OpenDisplaySettingsDialog(ev, fFrame);
  942.             fClockPart->AdjustDialogs(ev);
  943.             wasHandled = kODTrue;
  944.             break;
  945.         */
  946.         case cNewView:
  947.             fClockPart->OpenInitialWindow(ev);
  948.             fWindowState->SetDefaultWindowTitles(ev, fFrame->GetStorageUnit(ev)->GetDraft(ev));
  949.             wasHandled = kODTrue;
  950.             break;
  951.             default:
  952.                 wasHandled = kODFalse;
  953.                 break;
  954.         }
  955.     if (wasHandled)
  956.         return kODTrue;
  957.     else
  958.         return ClockFrame::HandleMenuEvent(ev, event);
  959. }
  960.  
  961.  
  962.  
  963.                 
  964. //------------------------------------------------------------------------------
  965. // ClockTimeFrame:  AdjustFrameShape
  966. //------------------------------------------------------------------------------
  967.  
  968.  
  969. void ClockTimeFrame::AdjustFrameShape(Environment *ev)
  970. {
  971.     if (fFrame->IsRoot(ev))
  972.     {
  973.         fFrame-> Invalidate(ev, kODNULL, kODNULL);
  974.         this->FitToFrameShape(ev);
  975.         return;
  976.     }
  977.     
  978.     Rect qdr;
  979.     fClockPart->CalcClockBounds(qdr);
  980.     ODRect r(qdr);
  981.  
  982.     TempODShape oldShape = fFrame->AcquireFrameShape(ev, kODNULL);
  983.     TempODShape wantShape = fFrame->CreateShape(ev);
  984.     
  985.     wantShape->SetRectangle(ev, &r);
  986.         
  987.     if ( !wantShape->IsSameAs(ev, oldShape) )
  988.     {    
  989.         //fFrame-> Invalidate(ev, kODNULL, kODNULL); // $$$$$ container responsible for old shape
  990.         
  991.         ODShape* gotShape = fFrame -> RequestFrameShape(ev,  wantShape, kODNULL );
  992.         ODReleaseObject(ev, gotShape);
  993.  
  994.         this->FitToFrameShape(ev); // Adjust used shape to frame shape
  995.     }
  996.  
  997.     fFrame-> Invalidate(ev, kODNULL, kODNULL);
  998. }
  999.  
  1000. void ClockTimeFrame::FrameShapeChanged(Environment *ev)
  1001. {
  1002.     fFrame-> Invalidate(ev, kODNULL, kODNULL);
  1003.     this->FitToFrameShape(ev);
  1004. }
  1005.  
  1006. static inline short Width(const Rect& r)
  1007. {
  1008.     return r.right - r.left;
  1009. }
  1010.  
  1011. static inline short Height(const Rect& r)
  1012. {
  1013.     return r.bottom - r.top;
  1014. }
  1015.  
  1016. static inline void CenterRect(const Rect& outer, Rect& inner)
  1017. {
  1018.     short x = (Width(outer) - Width(inner)) / 2;
  1019.     short y = (Height(outer) - Height(inner)) / 2;
  1020.     
  1021.     inner.right += x - inner.left;
  1022.     inner.left = x;
  1023.     inner.bottom += y - inner.top;
  1024.     inner.top = y;
  1025. }
  1026.  
  1027.  
  1028.  
  1029. void ClockTimeFrame::FitToFrameShape(Environment *ev)
  1030. {
  1031.     // Update used shape of frame and active shape of all facets
  1032.     // invalidate frame shape
  1033.     // invalidate active border
  1034.     
  1035.     Rect frameShapeRect;
  1036.     Rect usedShapeRect;
  1037.     ODShape* newUsedShape = kODNULL;
  1038.     
  1039.     {
  1040.         TempODShape frameShape = fFrame->AcquireFrameShape(ev, kODNULL);
  1041.         ODRgnHandle shapeRegion = frameShape->GetQDRegion(ev);
  1042.         frameShapeRect = (*shapeRegion)->rgnBBox;
  1043.     }
  1044.         
  1045.     if (fClockPart->IsAnalog())
  1046.     {
  1047.         if (fFrame->IsRoot(ev))
  1048.         {
  1049.             frameShapeRect.right = frameShapeRect.right - 16;
  1050.             frameShapeRect.bottom = frameShapeRect.bottom - 16;
  1051.         }
  1052.         usedShapeRect = frameShapeRect;
  1053.         if (usedShapeRect.bottom > usedShapeRect.right)
  1054.             usedShapeRect.bottom = usedShapeRect.right;
  1055.         else
  1056.             usedShapeRect.right = usedShapeRect.bottom;
  1057.             
  1058.     }
  1059.     else
  1060.     {
  1061.         fClockPart->CalcClockBounds(usedShapeRect);
  1062.     }
  1063.     if (fClockPart->IsAnalog())
  1064.         CenterRect(frameShapeRect, usedShapeRect);
  1065.  
  1066.     if (fClockPart->IsAnalog())
  1067.     {
  1068.         /*
  1069.         ODRect u(usedShapeRect);
  1070.         newUsedShape = fFrame->CreateShape(ev);
  1071.         newUsedShape->SetRectangle(ev, &u);
  1072.         */
  1073.         newUsedShape = fClockPart->CreateOvalShape(ev, fFrame, usedShapeRect);
  1074.     }
  1075.     else
  1076.     {
  1077.         ODRect u(usedShapeRect);
  1078.         newUsedShape = fFrame->CreateShape(ev);
  1079.         newUsedShape->SetRectangle(ev, &u);
  1080.     }
  1081.     
  1082.     /* This is an alternative to the SetOrigin calls. But then we need to
  1083.       undo the transformation to draw the border. It would be nice if CFocus
  1084.       provide an easy way to mix internal/external transforms.
  1085.       
  1086.     ODTransform* internal = fFrame->CreateTransform(ev);
  1087.     Point offset; 
  1088.     offset.h = usedShapeRect.left;
  1089.     offset.v = usedShapeRect.top;
  1090.     internal->SetQDOffset(ev, &offset);
  1091.     fFrame->ChangeInternalTransform(ev, internal, kODNULL);
  1092.     internal->Release(ev);
  1093.     */
  1094.     
  1095.     fFrame->ChangeUsedShape(ev, newUsedShape, kODNULL);
  1096.     
  1097.     ODShape* activeShape = newUsedShape->Copy(ev);
  1098.     /*if (fHasFoci)
  1099.     {
  1100.         ODRect u2(usedShapeRect);
  1101.         activeShape->SetRectangle(ev, &u2);
  1102.     }*/
  1103.     ODFrameFacetIterator* fi = fFrame->CreateFacetIterator(ev);
  1104.     for(ODFacet* facet = fi->First(ev); fi->IsNotComplete(ev);
  1105.             facet = fi->Next(ev))
  1106.     {
  1107.         facet->ChangeActiveShape(ev,activeShape, kODNULL);
  1108.     }
  1109.     ODDeleteObject(fi);
  1110.     activeShape->Release(ev);
  1111.     
  1112.     newUsedShape->Release(ev);
  1113. }
  1114.  
  1115. void ClockTimeFrame::FacetAdded(Environment* ev, ODFacet* facet) 
  1116. {
  1117.     ClockFrame::FacetAdded(ev, facet);
  1118.     this->AdjustFrameShape(ev);
  1119. }
  1120.  
  1121. void ClockTimeFrame::Add(Environment* ev)
  1122. {
  1123.     ClockFrame::Add(ev);
  1124.     fClockPart->AddContentFrame(ev, fFrame);
  1125.     fDispatcher->RegisterIdle(ev, fClockPart->GetPartWrapper(), fFrame, kCPIdleFrequency );
  1126. }
  1127.  
  1128. void ClockTimeFrame::Connect(Environment* ev)
  1129. {
  1130.     ClockFrame::Connect(ev);
  1131.     fClockPart->AddContentFrame(ev, fFrame);
  1132.     fDispatcher->RegisterIdle(ev, fClockPart->GetPartWrapper(), fFrame, kCPIdleFrequency );
  1133. }
  1134.  
  1135. void ClockTimeFrame::Remove(Environment* ev)
  1136. {
  1137.     fDispatcher->UnregisterIdle(ev, fClockPart->GetPartWrapper(), fFrame );
  1138.     gClockGlobals->RemovingFrame(ev, fFrame);
  1139.     fClockPart->RemoveContentFrame(ev, fFrame);
  1140.     ClockFrame::Remove(ev);
  1141. }
  1142.  
  1143. void ClockTimeFrame::Close(Environment* ev)
  1144. {
  1145.     fDispatcher->UnregisterIdle(ev, fClockPart->GetPartWrapper(), fFrame );
  1146.     gClockGlobals->RemovingFrame(ev, fFrame);
  1147.     fClockPart->RemoveContentFrame(ev, fFrame);
  1148.     ClockFrame::Close(ev);
  1149. }
  1150.  
  1151. //----------------------------------------------------------------------------------------
  1152. // ClockTimeFrame::DrawClockFace
  1153. //----------------------------------------------------------------------------------------
  1154.  
  1155. void ClockTimeFrame::DrawClockFace(Environment* ev, ODFacet* facet)
  1156. {
  1157.     Rect frameRect, usedRect;
  1158.     {
  1159.         TempODShape frameShape = fFrame->AcquireFrameShape(ev, kODNULL);
  1160.         TempODShape usedShape = fFrame->AcquireUsedShape(ev, kODNULL);
  1161.         ODRgnHandle frameRegion = frameShape->GetQDRegion(ev);
  1162.         frameRect = (*frameRegion)->rgnBBox;
  1163.         ODRgnHandle usedRegion = usedShape->GetQDRegion(ev);
  1164.         usedRect = (*usedRegion)->rgnBBox;
  1165.     }
  1166.     
  1167.     if (fClockPart->IsAnalog())
  1168.     {
  1169.         if (fFrame->IsRoot(ev))
  1170.             ::EraseRect(&frameRect);
  1171.         else
  1172.             ::EraseOval(&usedRect);
  1173.             //::EraseRect(&usedRect);
  1174.         
  1175.         this->DrawAnalogFace(ev, facet);
  1176.     }
  1177.     else
  1178.     {
  1179.         if (fFrame->IsRoot(ev))
  1180.             ::EraseRect(&frameRect);
  1181.         else
  1182.             ::EraseRect(&usedRect);
  1183.         
  1184.         ::FrameRect(&usedRect);
  1185.     }
  1186. }
  1187.  
  1188. //----------------------------------------------------------------------------------------
  1189. // ClockTimeFrame::DrawAnalogFace
  1190. //----------------------------------------------------------------------------------------
  1191.  
  1192. void ClockTimeFrame::DrawAnalogFace(Environment* ev, ODFacet* facet)
  1193. {
  1194.     Point currentPenSize = ODQDGlobals.thePort->pnSize;
  1195.     // TextStyle currentTextStyle;
  1196.     Point centerPoint;
  1197.     Point newPoint;
  1198.     Point tickPoint;
  1199.     ODSShort radius;
  1200.     ODSShort angle = 0;
  1201.     ODSShort fiveMinute = 0;
  1202.     double_t radians;
  1203.     
  1204.     // ::GetPortTextStyle(¤tTextStyle);
  1205.     
  1206.     Rect clockRect;
  1207.     {
  1208.         TempODShape usedShape = fFrame->AcquireUsedShape(ev, kODNULL);
  1209.         ODRgnHandle shapeRegion = usedShape->GetQDRegion(ev);
  1210.         clockRect = (*shapeRegion)->rgnBBox;
  1211.     }
  1212.         
  1213.     centerPoint.h = (clockRect.right - clockRect.left) / 2;
  1214.     centerPoint.v = (clockRect.bottom - clockRect.top) / 2;
  1215.     radius = centerPoint.h;
  1216.  
  1217.     ::EraseOval(&clockRect);
  1218.  
  1219.     ::PenSize(2,2);
  1220.     ::FrameOval(&clockRect);
  1221.     ::PenSize(1,1);
  1222.     
  1223.     ::TextFont(helvetica);
  1224.     //::TextFace(italic);
  1225.     ::TextSize(radius / 10);
  1226.  
  1227.     /* $$$$$ Added */
  1228.     Point oldOrigin;
  1229.     Point newOrigin;
  1230.     oldOrigin.h = ODQDGlobals.thePort->portRect.left;
  1231.     oldOrigin.v = ODQDGlobals.thePort->portRect.top;
  1232.     newOrigin.h = oldOrigin.h - clockRect.left;
  1233.     newOrigin.v = oldOrigin.v - clockRect.top;
  1234.     SetOrigin(newOrigin.h,newOrigin.v);
  1235.     // */
  1236.     
  1237.     Str255 clockFaceString = "\pOpenDoc™";
  1238.     //FW_CAcquireASLMResourceAccess aq;
  1239.     //::GetIndString(clockFaceString, kClockPartStrings, kClockFaceString);
  1240.     
  1241.     ::MoveTo(((clockRect.right - clockRect.left) - ::StringWidth(clockFaceString)) / 2, (clockRect.bottom - clockRect.top) / 4);
  1242.     ::DrawString(clockFaceString);
  1243.  
  1244.  
  1245.     //!!!!! Should save/restore
  1246.     TextFace( normal );
  1247.     TextFont( geneva );
  1248.     TextMode( srcOr );
  1249.     TextSize( 12 );
  1250.     
  1251.     
  1252.     
  1253.     // Use the symmetry of the clock face to speed up the calculations for drawing the face
  1254.     // We only need to calculate points for 45 degrees of the circle.  The remaining points can
  1255.     // be inferred from these points
  1256.     while (angle < 45)
  1257.     {
  1258.         // convert angle to radians
  1259.         radians = (90 - angle) / (360 / (2 * pi));
  1260.         newPoint.h = (short)::rint((radius * cos(radians)) + centerPoint.h);
  1261.         newPoint.v = (short)::rint((radius * sin(radians)) + centerPoint.v);
  1262.         
  1263.         if (fiveMinute == 0)
  1264.         {
  1265.             short hourTick = radius - (radius / 10);
  1266.             tickPoint.h = (short)::rint((hourTick * cos(radians)) + centerPoint.h);
  1267.             tickPoint.v = (short)::rint((hourTick * sin(radians)) + centerPoint.v);
  1268.             fiveMinute = 4;
  1269.         }
  1270.         else
  1271.         {
  1272.             short minuteTick = radius - (radius / 20);
  1273.             tickPoint.h = (short)::rint((minuteTick * cos(radians)) + centerPoint.h);
  1274.             tickPoint.v = (short)::rint((minuteTick * sin(radians)) + centerPoint.v);
  1275.             fiveMinute--;
  1276.         }
  1277.  
  1278.         ::MoveTo(newPoint.h - 1, newPoint.v - 1);
  1279.         ::LineTo(tickPoint.h - 1, tickPoint.v - 1);
  1280.         
  1281.         ::MoveTo((clockRect.right-clockRect.left) - newPoint.h, newPoint.v - 1);
  1282.         ::LineTo((clockRect.right-clockRect.left) - tickPoint.h, tickPoint.v - 1);
  1283.         
  1284.         ::MoveTo(newPoint.h - 1, (clockRect.bottom-clockRect.top) - newPoint.v);
  1285.         ::LineTo(tickPoint.h - 1, (clockRect.bottom-clockRect.top) - tickPoint.v);
  1286.  
  1287.         ::MoveTo((clockRect.right-clockRect.left) - newPoint.h, (clockRect.bottom-clockRect.top) - newPoint.v);
  1288.         ::LineTo((clockRect.right-clockRect.left) - tickPoint.h, (clockRect.bottom-clockRect.top) - tickPoint.v);
  1289.  
  1290.         ::MoveTo(newPoint.v - 1, newPoint.h - 1);
  1291.         ::LineTo(tickPoint.v - 1, tickPoint.h - 1);
  1292.         
  1293.         ::MoveTo((clockRect.bottom-clockRect.top) - newPoint.v, newPoint.h - 1);
  1294.         ::LineTo((clockRect.bottom-clockRect.top) - tickPoint.v, tickPoint.h - 1);
  1295.         
  1296.         ::MoveTo(newPoint.v - 1, (clockRect.right-clockRect.left) - newPoint.h);
  1297.         ::LineTo(tickPoint.v - 1, (clockRect.right-clockRect.left) - tickPoint.h);
  1298.  
  1299.         ::MoveTo((clockRect.bottom-clockRect.top) - newPoint.v, (clockRect.right-clockRect.left) - newPoint.h);
  1300.         ::LineTo((clockRect.bottom-clockRect.top) - tickPoint.v, (clockRect.right-clockRect.left) - tickPoint.h);
  1301.  
  1302.         angle += 6;
  1303.     }
  1304.     
  1305.     SetOrigin(oldOrigin.h,oldOrigin.v);
  1306.     
  1307.     
  1308.     ::PenSize(currentPenSize.h, currentPenSize.v);
  1309.     // ::SetPortTextStyle(¤tTextStyle);
  1310. }
  1311.  
  1312. //----------------------------------------------------------------------------------------
  1313. // ClockTimeFrame::DrawClockHands
  1314. //----------------------------------------------------------------------------------------
  1315. void ClockTimeFrame::DrawClockHands(Environment* ev, ODFacet* facet, ODULong tickCount)
  1316. {
  1317.     ODSShort currentPenMode = ODQDGlobals.thePort->pnMode;
  1318.     Point centerPoint;
  1319.     DateTimeRec time;
  1320.     
  1321.     Rect clockRect;
  1322.     {
  1323.         TempODShape usedShape = fFrame->AcquireUsedShape(ev, kODNULL);
  1324.         ODRgnHandle shapeRegion = usedShape->GetQDRegion(ev);
  1325.         clockRect = (*shapeRegion)->rgnBBox;
  1326.     }
  1327.  
  1328.     /* $$$$$ Added */
  1329.     Point oldOrigin;
  1330.     Point newOrigin;
  1331.     oldOrigin.h = ODQDGlobals.thePort->portRect.left;
  1332.     oldOrigin.v = ODQDGlobals.thePort->portRect.top;
  1333.     newOrigin.h = oldOrigin.h - clockRect.left;
  1334.     newOrigin.v = oldOrigin.v - clockRect.top;
  1335.     SetOrigin(newOrigin.h,newOrigin.v);
  1336.     // */
  1337.     
  1338.     centerPoint.h = (clockRect.right - clockRect.left) / 2;
  1339.     centerPoint.v = (clockRect.bottom - clockRect.top) / 2;
  1340.     
  1341.     ::SecondsToDate(tickCount, &time);
  1342.     
  1343.     PenMode(patXor);
  1344.     this->DrawSecondHand(&clockRect, ¢erPoint, centerPoint.h, time.second);
  1345.     this->DrawMinuteHand(&clockRect, ¢erPoint, centerPoint.h, time.minute);
  1346.  
  1347.     if (time.hour > 11)
  1348.     this->DrawHourHand(&clockRect, ¢erPoint, centerPoint.h, time.hour - 12, time.minute);
  1349.     else
  1350.     this->DrawHourHand(&clockRect, ¢erPoint, centerPoint.h, time.hour, time.minute);
  1351.  
  1352.     ::PenMode(currentPenMode);
  1353.     
  1354.     //$$$$$Added
  1355.     SetOrigin(oldOrigin.h, oldOrigin.v);
  1356. }
  1357.  
  1358. //----------------------------------------------------------------------------------------
  1359. // ClockTimeFrame::UpdateClockHands
  1360. //----------------------------------------------------------------------------------------
  1361. void ClockTimeFrame::UpdateClockHands(Environment* ev, ODFacet* facet, ODULong tickCount)
  1362. {
  1363.     ODSShort currentPenMode = ODQDGlobals.thePort->pnMode;
  1364.     Point centerPoint;
  1365.     DateTimeRec time;
  1366.     DateTimeRec lastTime;
  1367.     
  1368.     
  1369.  
  1370.  
  1371.      ::GetDateTime(&tickCount);
  1372.     ::SecondsToDate(tickCount, &time);
  1373.     ::SecondsToDate(fLastTime, &lastTime);
  1374.     
  1375.     Rect clockRect;
  1376.     {
  1377.         TempODShape usedShape = fFrame->AcquireUsedShape(ev, kODNULL);
  1378.         ODRgnHandle shapeRegion = usedShape->GetQDRegion(ev);
  1379.         clockRect = (*shapeRegion)->rgnBBox;
  1380.     }
  1381.     
  1382.     /* $$$$$ Added */
  1383.     Point oldOrigin;
  1384.     Point newOrigin;
  1385.     oldOrigin.h = ODQDGlobals.thePort->portRect.left;
  1386.     oldOrigin.v = ODQDGlobals.thePort->portRect.top;
  1387.     newOrigin.h = oldOrigin.h - clockRect.left;
  1388.     newOrigin.v = oldOrigin.v - clockRect.top;
  1389.     SetOrigin(newOrigin.h,newOrigin.v);
  1390.     // */
  1391.  
  1392.     centerPoint.h = (clockRect.right - clockRect.left) / 2;
  1393.     centerPoint.v = (clockRect.bottom - clockRect.top) / 2;
  1394.     
  1395.     ::PenMode(patXor);
  1396.     
  1397.     // Since we're called every second go ahead and update the second hand
  1398.     this->DrawSecondHand(&clockRect, ¢erPoint, centerPoint.h, lastTime.second);
  1399.     this->DrawSecondHand(&clockRect, ¢erPoint, centerPoint.h, time.second);
  1400.  
  1401.     if (lastTime.minute != time.minute)
  1402.     {
  1403.         this->DrawMinuteHand(&clockRect, ¢erPoint, centerPoint.h, lastTime.minute);
  1404.         this->DrawMinuteHand(&clockRect, ¢erPoint, centerPoint.h, time.minute);
  1405.         
  1406.         if (lastTime.hour > 11)
  1407.             this->DrawHourHand(&clockRect, ¢erPoint, centerPoint.h, lastTime.hour - 12, lastTime.minute);
  1408.         else
  1409.             this->DrawHourHand(&clockRect, ¢erPoint, centerPoint.h, lastTime.hour, lastTime.minute);
  1410.  
  1411.         if (time.hour > 11)
  1412.             this->DrawHourHand(&clockRect, ¢erPoint, centerPoint.h, time.hour - 12, time.minute);
  1413.         else
  1414.             this->DrawHourHand(&clockRect, ¢erPoint, centerPoint.h, time.hour, time.minute);
  1415.     }
  1416.     
  1417.     ::PenMode(currentPenMode);
  1418.     //$$$$$Added
  1419.     SetOrigin(oldOrigin.h, oldOrigin.v);
  1420. }
  1421.  
  1422. //----------------------------------------------------------------------------------------
  1423. // ClockTimeFrame::DrawHourHand
  1424. //----------------------------------------------------------------------------------------
  1425. void ClockTimeFrame::DrawHourHand(Rect* clockRect, Point* centerPoint, ODSShort radius, ODSShort hour, ODSShort minute)
  1426. {
  1427.     Point currentPenSize = ODQDGlobals.thePort->pnSize;
  1428.     Point newPoint;
  1429.     double_t radians;
  1430.     ODSShort hourRadius = radius / 2;        // Make the hour hand short and stubby
  1431.     
  1432.     // Divide the clock face into degrees.  Hour hand falls on every five minutes or every 30 degrees
  1433.     radians = ((hour * 30) + (minute / 2)) / (360 / (2 * pi));
  1434.     newPoint.h = (short)::rint((hourRadius * ::sin(radians)) + centerPoint->h);
  1435.     newPoint.v = clockRect->bottom-clockRect->top - ((short)::rint((hourRadius * ::cos(radians)) + centerPoint->v));
  1436.  
  1437.     ::PenSize(3,3);
  1438.     ::MoveTo(centerPoint->h, centerPoint->v);
  1439.     ::LineTo(newPoint.h - 1, newPoint.v);
  1440.     ::PenSize(currentPenSize.h, currentPenSize.v);
  1441. }
  1442.  
  1443. //----------------------------------------------------------------------------------------
  1444. // ClockTimeFrame::DrawMinuteHand
  1445. //----------------------------------------------------------------------------------------
  1446. void ClockTimeFrame::DrawMinuteHand(Rect* clockRect, Point* centerPoint, ODSShort radius, ODSShort minute)
  1447. {
  1448.     Point currentPenSize = ODQDGlobals.thePort->pnSize;
  1449.     Point newPoint;
  1450.     double_t radians;
  1451.     ODSShort minuteRadius = radius - (radius / 20);  // Make the minute hand longer than the hour hand
  1452.  
  1453.     // Divide the clock face into degrees.  (360 degrees divided by 60 minutes is 6 degrees per minute)
  1454.     radians = (minute * 6) / (360 / (2 * pi));
  1455.     newPoint.h = (short)::rint((minuteRadius * ::sin(radians)) + centerPoint->h);
  1456.     newPoint.v = clockRect->bottom-clockRect->top - ((short)::rint((minuteRadius * ::cos(radians)) + centerPoint->v));
  1457.  
  1458.     ::PenSize(2,2);
  1459.     ::MoveTo(centerPoint->h, centerPoint->v);
  1460.     ::LineTo(newPoint.h - 1, newPoint.v);
  1461.     ::PenSize(currentPenSize.h, currentPenSize.v);
  1462. }
  1463.  
  1464. //----------------------------------------------------------------------------------------
  1465. // ClockTimeFrame::DrawSecondHand
  1466. //----------------------------------------------------------------------------------------
  1467. void ClockTimeFrame::DrawSecondHand(Rect* clockRect, Point* centerPoint, ODSShort radius, ODSShort second)
  1468. {
  1469.     Point currentPenSize = ODQDGlobals.thePort->pnSize;
  1470.     Point newPoint;
  1471.  
  1472.     double_t radians;
  1473.     ODSShort secondRadius = radius - (radius / 40);    // A nice sweeping second hand
  1474.  
  1475.     // Divide the clock face into degrees.  (360 degrees divided by 60 seconds is 6 degrees per second)
  1476.     radians = (second * 6) / (360 / (2 * pi));
  1477.     newPoint.h = (short)::rint((secondRadius * ::sin(radians)) + centerPoint->h);
  1478.     newPoint.v = clockRect->bottom-clockRect->top - ((short)::rint((secondRadius * ::cos(radians)) + centerPoint->v));
  1479.  
  1480.     ::PenSize(1,1);
  1481.     ::MoveTo(centerPoint->h, centerPoint->v);
  1482.     ::LineTo(newPoint.h - 1, newPoint.v);
  1483.     ::PenSize(currentPenSize.h, currentPenSize.v);
  1484. }
  1485.  
  1486.  
  1487. //=========================================================================
  1488. // ClockDialogFrame
  1489. //=========================================================================
  1490.  
  1491. ClockDialogFrame::ClockDialogFrame()
  1492. {
  1493. }
  1494.  
  1495. ClockDialogFrame::~ClockDialogFrame()
  1496. {
  1497. }
  1498.  
  1499. void ClockDialogFrame::InitClockDialogFrame(Environment* ev, 
  1500.                                             ODSession* session,
  1501.                                             ODFrame* frame, 
  1502.                                             ClockPart* clockPart)
  1503. {
  1504.     this->InitClockFrame(ev, session, frame, clockPart);
  1505.  
  1506.     fFocusSet->Add(ev, fKeyFocus);
  1507.     fFocusSet->Add(ev, fMenuFocus);
  1508.     
  1509.     fShouldHideOnSuspend = kODTrue;
  1510. }
  1511.  
  1512. void ClockDialogFrame::Draw(Environment* ev, ODFacet* facet, ODShape* invalShape)
  1513. {
  1514.     ODWindow* odWindow = facet ? facet->GetWindow(ev) : kODNULL;
  1515.     WindowPtr window = odWindow ? odWindow->GetPlatformWindow(ev) : kODNULL;
  1516.     if (window)    
  1517.         DrawDialog(window);
  1518.     else
  1519.         WARN("dialog ptr is NULL");
  1520. }
  1521.  
  1522. void ClockDialogFrame::Idle(Environment* ev, ODEventData* event)
  1523. {
  1524.     if (IsDialogEvent((const EventRecord *)event))
  1525.     {
  1526.         short itemHit;
  1527.         DialogPtr dialog;
  1528.         ODBoolean wasHandled = DialogSelect((const EventRecord *)event, &dialog, &itemHit);
  1529.     }
  1530. }
  1531.  
  1532. void ClockDialogFrame::Add(Environment* ev)
  1533. {
  1534.     ClockFrame::Add(ev);
  1535. #if defined(ODDebug) && ODDebugLayers
  1536.     somPrintf("ClockDialogFrame::Add. Adding Dialog Frame\n");
  1537. #endif
  1538.     gClockGlobals->AddDialogFrame(ev, fFrame);
  1539. }
  1540.  
  1541. void ClockDialogFrame::Connect(Environment* ev)
  1542. {
  1543.     ClockFrame::Connect(ev);
  1544.     gClockGlobals->AddDialogFrame(ev, fFrame);
  1545. }
  1546.  
  1547. void ClockDialogFrame::Remove(Environment* ev)
  1548. {
  1549.     ClockFrame::Remove(ev);
  1550.     gClockGlobals->RemoveDialogFrame(ev, fFrame);
  1551. }
  1552.  
  1553. void ClockDialogFrame::Close(Environment* ev)
  1554. {
  1555.     ClockFrame::Close(ev);
  1556.     gClockGlobals->RemoveDialogFrame(ev, fFrame);
  1557. }
  1558.  
  1559. //=========================================================================
  1560. // ClockSynchroDialogFrame
  1561. //=========================================================================
  1562.  
  1563. ClockSynchroDialogFrame::ClockSynchroDialogFrame()
  1564. {
  1565. }
  1566.  
  1567. ClockSynchroDialogFrame::~ClockSynchroDialogFrame()
  1568. {
  1569. }
  1570.  
  1571. void ClockSynchroDialogFrame::InitClockSynchroDialogFrame(Environment* ev, 
  1572.                                                             ODSession* session,
  1573.                                                             ODFrame* frame, 
  1574.                                                             ClockPart* clockPart)
  1575. {
  1576.     this->InitClockDialogFrame(ev, session, frame, clockPart);
  1577.     fNeedsFoci = kODTrue;
  1578. }
  1579.  
  1580. ODBoolean ClockSynchroDialogFrame::HandleMouseDown(Environment* ev, ODFacet* facet, ODEventData* event)
  1581. {
  1582.     ODBoolean wasHandled = kODFalse;
  1583.  
  1584.     if (IsDialogEvent((const EventRecord *)event))
  1585.     {
  1586.         short itemHit;
  1587.         DialogPtr dialog;
  1588.         wasHandled = DialogSelect((const EventRecord *)event, &dialog, &itemHit);
  1589.         ODWindow* window = fWindowState->AcquireODWindow(ev, dialog); // -- TÇ: released by CloseAndRemove
  1590.         
  1591.         if (itemHit == cancel)
  1592.         {
  1593.             ClockPart* clockPart = fClockPart; // "this" is about to go away
  1594.             fArbitrator->RelinquishFocus(ev, fModalFocus, fFrame);
  1595.             window->CloseAndRemove(ev);
  1596.             //!!! Reenable entire Menus. MenuBar object needs more support for this
  1597.             // ODReleaseObject(ev, window); // -- TÇ: released by CloseAndRemove
  1598.             
  1599.             clockPart->GetMenuBar()->EnableAll(ev);
  1600.  
  1601.             //clockPart->GetMenuBar()->EnableCommand(ev,  kODCommandAbout, kODTrue ) ;
  1602.             InvalMenuBar();
  1603.         }
  1604.         else
  1605.             ODReleaseObject(ev, window);
  1606.     }
  1607.  
  1608.     return wasHandled;
  1609. }
  1610.  
  1611. void  ClockSynchroDialogFrame::AdjustMenus(Environment *ev)
  1612. {
  1613.     fClockPart->GetMenuBar()->EnableCommand(ev,  kODCommandAbout, kODFalse ) ;
  1614.     fClockPart->GetMenuBar()->EnableCommand(ev,  kODCommandCopy, kODTrue ) ;
  1615.     fClockPart->GetMenuBar()->EnableCommand(ev,  kODCommandUndo, kODFalse ) ;
  1616.     fClockPart->GetMenuBar()->EnableCommand(ev,  kODCommandRedo, kODFalse ) ;
  1617. }
  1618.  
  1619. //=========================================================================
  1620. // ClockAlarmSettingsDialogFrame
  1621. //=========================================================================
  1622.  
  1623. ClockAlarmSettingsDialogFrame::ClockAlarmSettingsDialogFrame()
  1624. {
  1625. }
  1626.  
  1627. ClockAlarmSettingsDialogFrame::~ClockAlarmSettingsDialogFrame()
  1628. {
  1629. }
  1630.  
  1631. void ClockAlarmSettingsDialogFrame::InitClockAlarmSettingsDialogFrame(Environment* ev, 
  1632.                                                             ODSession* session,
  1633.                                                             ODFrame* frame, 
  1634.                                                             ClockPart* clockPart)
  1635. {
  1636.     this->InitClockDialogFrame(ev, session, frame, clockPart);
  1637.     fNeedsFoci = kODTrue;
  1638.     fShouldDeleteWindow = kODFalse; // Because its shared
  1639. }
  1640.  
  1641. ODBoolean ClockAlarmSettingsDialogFrame::HandleMouseDown(Environment* ev, ODFacet* facet, ODEventData* event)
  1642. {
  1643.     ODBoolean wasHandled = kODFalse;
  1644.  
  1645.     if (IsDialogEvent((const EventRecord *)event))
  1646.     {
  1647.         short itemHit;
  1648.         ODSShort     itemType;
  1649.         ODSShort    checkbox;
  1650.         Handle        itemHandle;
  1651.         Rect        scratchRect;
  1652.  
  1653.         DialogPtr dialog;
  1654.         wasHandled = DialogSelect((const EventRecord *)event, &dialog, &itemHit);
  1655.         
  1656.         if (itemHit == kClock_SettingsCheckBoxID)
  1657.         {
  1658.             GetDialogItem(dialog, itemHit, &itemType, &itemHandle, &scratchRect);
  1659.             checkbox = GetControlValue((ControlHandle)itemHandle);
  1660.             checkbox = 1 - checkbox;
  1661.             SetControlValue((ControlHandle)itemHandle,checkbox);
  1662.             fClockPart->ToggleAlarm();
  1663.         }
  1664.     }
  1665.  
  1666.     return wasHandled;
  1667. }
  1668.  
  1669. //=========================================================================
  1670. // ClockDisplaySettingsDialogFrame
  1671. //=========================================================================
  1672.  
  1673. ClockDisplaySettingsDialogFrame::ClockDisplaySettingsDialogFrame()
  1674. {
  1675. }
  1676.  
  1677. ClockDisplaySettingsDialogFrame::~ClockDisplaySettingsDialogFrame()
  1678. {
  1679. }
  1680.  
  1681. void ClockDisplaySettingsDialogFrame::InitClockDisplaySettingsDialogFrame(Environment* ev, 
  1682.                                                             ODSession* session,
  1683.                                                             ODFrame* frame, 
  1684.                                                             ClockPart* clockPart)
  1685. {
  1686.     this->InitClockDialogFrame(ev, session, frame, clockPart);
  1687.     fNeedsFoci = kODTrue;
  1688.     fShouldDeleteWindow = kODFalse; // Because its shared
  1689. }
  1690.  
  1691. ODBoolean ClockDisplaySettingsDialogFrame::HandleMouseDown(Environment* ev, ODFacet* facet, ODEventData* event)
  1692. {
  1693.     ODBoolean wasHandled = kODFalse;
  1694.  
  1695.     if (IsDialogEvent((const EventRecord *)event))
  1696.     {
  1697.         short itemHit;
  1698.         ODSShort     itemType;
  1699.         ODSShort    checkbox;
  1700.         Handle        itemHandle;
  1701.         Rect        scratchRect;
  1702.  
  1703.         DialogPtr dialog;
  1704.         wasHandled = DialogSelect((const EventRecord *)event, &dialog, &itemHit);
  1705.         
  1706.         if (itemHit == kClock_SettingsCheckBoxID)
  1707.         {
  1708.             GetDialogItem(dialog, itemHit, &itemType, &itemHandle, &scratchRect);
  1709.             checkbox = GetControlValue((ControlHandle)itemHandle);
  1710.             checkbox = 1 - checkbox;
  1711.             SetControlValue((ControlHandle)itemHandle,checkbox);
  1712.             fClockPart->SendClockModeEvent(ev, !fClockPart->IsAnalog(), 
  1713.                             fClockPart->GetFirstFrame());
  1714.         }
  1715.     }
  1716.  
  1717.     return wasHandled;
  1718. }
  1719.  
  1720. void ClockDisplaySettingsDialogFrame::Add(Environment* ev)
  1721. {
  1722. #if defined(ODDebug) && ODDebugLayers
  1723.     somPrintf("ClockDisplaySettingsDialogFrame::Add\n");
  1724. #endif
  1725.     ClockDialogFrame::Add(ev);
  1726.  
  1727.     fClockPart->AdjustDialogs(ev);
  1728. }
  1729.  
  1730. void ClockDisplaySettingsDialogFrame::Adjust(Environment* ev)
  1731. {
  1732.     ODSShort     itemType;
  1733.     Handle        itemHandle;
  1734.     Rect        scratchRect;
  1735.  
  1736.     ODWindow* window = fFrame->AcquireWindow(ev);
  1737.     DialogPtr dialog = window ? window->GetPlatformWindow(ev) : kODNULL;
  1738.     if (dialog)
  1739.     {
  1740.         GetDialogItem(dialog, kClock_SettingsCheckBoxID, &itemType, &itemHandle, &scratchRect);
  1741.         if (fClockPart->IsAnalog())
  1742.             SetControlValue((ControlHandle)itemHandle,1);
  1743.         else    
  1744.             SetControlValue((ControlHandle)itemHandle,0);
  1745.     }
  1746.     ODReleaseObject(ev, window);
  1747. }
  1748.